﻿@using Smartstore.Web.Models.Search

@model SearchResultModel

@{
    var hitGroups = Model.HitGroups.Where(x => x.Hits.Count > 0).OrderBy(x => x.Ordinal).ToArray();
    var numProducts = Model.TopProducts.Items.Count;
    var numHits = hitGroups.Sum(x => x.Hits.Count);
    var hasContent = numProducts > 0 || hitGroups.Length > 0;
    var isMultiCol = hasContent && hitGroups.Length > 0 && (numHits + numProducts > 8 || hitGroups.Length > 1);
}

@if (!hasContent)
{
    <div class="instasearch-no-hits">
        @Html.Raw(T("Search.NoResultsText"))
    </div>
}
else if (isMultiCol)
{
    <div class="row no-gutters instasearch-row">
        <div class="col col-sm-6 col-lg-7 instasearch-col">
            <h6 class="instasearch-group-header">@T("Search.Hits")</h6>
            <partial name="InstantSearch.TopProducts" model="Model" />
        </div>
        <div class="col col-sm-6 col-lg-5 instasearch-col">
            @foreach (var group in hitGroups)
            {
                <partial name="InstantSearch.HitGroup" model="group" />
            }
        </div>
    </div>
}
else
{
    if (Model.TopProducts.Items.Count > 0)
    {
        <h6 class="instasearch-group-header">@T("Search.Hits")</h6>
        <partial name="InstantSearch.TopProducts" model="Model" />
    }
    foreach (var group in hitGroups)
    {
        <partial name="InstantSearch.HitGroup" model="group" />
    }
}
